﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BIZ;
using DAL;

namespace SinhNhat.admin
{
    public partial class AdminService : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            ServiceBIZ serviceBIZ = new ServiceBIZ();
            CollectionPager1.DataSource = serviceBIZ.GetAll();
            CollectionPager1.BindToControl = grService;
            grService.DataSource = CollectionPager1.DataSourcePaged;
            grService.DataBind();
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            grService.RowCommand += new GridViewCommandEventHandler(grService_RowCommand);
        }

        void grService_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            Guid productID = WebUtils.ToGuid(e.CommandName);
            ServiceBIZ serviceBIZ = new ServiceBIZ();

            if (e.CommandArgument.Equals("True"))
            {
                serviceBIZ.ChangeStatus(productID, false);
            }
            else if (e.CommandArgument.Equals("False"))
            {
                serviceBIZ.ChangeStatus(productID, true);
            }

            LoadData();
        }
    }
}